/**
 * DaoXml.java
 *2013年11月5日下午7:10:55
 *LINKT
 */
package com.jskj.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.jskj.commons.DBConn;

/**
 * @author LINKT
 *
 */
public class DaoXml {

        /**
         * 插入加油站信息
         * @param doc
         * @return
         */
        public Document insertGas(Document doc) {
                Document d=null;
                String str="";
                Map<String, String> map=new HashMap<String, String>();
                Element e=doc.getRootElement();
                List<Element> list=e.elements("data");
                if (list.size()>0) {
                        for (Element element : list) {
                                map.put(element.attributeValue("name"), element.attributeValue("value"));
                        }
                        //存入数据库
                        DBConn conn=new DBConn();
                        if (conn.SelectSQLCount("select * from jyz where jyz_sh='"+map.get("jyz_sh")+"'")>0){
                                conn.ExecuteSQL("delete from jyz where jyz_sh='"+map.get("jyz_sh") +"'");
                        }
                        conn.ExecuteSQL("INSERT INTO [taxoil].[dbo].[jyz]([jyz_bh], [jyz_mc], [jyz_sh], [jyz_swjg], [jyz_xzqh], [jyz_dz], [jyz_lxr], [jyz_dh], [jyz_bz])"+
                                                   " VALUES('"+map.get("jyz_sh")+"','"+map.get("jyz_mc")+"','"+map.get("jyz_sh")+"','"+map.get("swjg_dm")+"','"+map.get("jyz_xzqh")+"','"+map.get("jyz_dz")+"','"+map.get("jyz_lxr")+"','"+map.get("jyz_dh")+"','N')");
                        conn.Close();
                        str="<?xml version=\"1.0\" encoding=\"GBK\"?>"
                                        + "<return>" + "<returnCode>1</returnCode>"
                                        + "<returnMessage>上传成功</returnMessage></return>";
                }else{
                        str="<?xml version=\"1.0\" encoding=\"GBK\"?>"
                                        + "<return>" + "<returnCode>0</returnCode>"
                                        + "<returnMessage>XML数据未发现data节点</returnMessage></return>";
                }
                try {
                        d=DocumentHelper.parseText(str);
                } catch (DocumentException e1) {
                        e1.printStackTrace();
                }
                return d;
        }
        /**
         * 插入油枪信息
         * @param doc
         * @return
         */
        public Document insertGun(Document doc) {
                Document d=null;
                String str="";
                Map<String, String> map=new HashMap<String, String>();
                Element e=doc.getRootElement();
                List<Element> list=e.elements("data");
                if (list.size()>0) {
                        for (Element element : list) {
                                map.put(element.attributeValue("name"), element.attributeValue("value"));
                        }
                        //存入数据库
                        DBConn conn=new DBConn();
                        if (conn.SelectSQLCount("select * from yq where xlh='"+map.get("yq_xlh") +"' and jjxh='"+map.get("yq_jjxh") +"'")>0){
                                conn.ExecuteSQL("delete from [taxoil].[dbo].[yq] where xlh='"+map.get("yq_xlh") +"' and jjxh='"+map.get("yq_jjxh") +"'");
                        }
                        conn.ExecuteSQL("INSERT INTO [taxoil].[dbo].[yq]([SWJG_DM], [yqbh], [yzbh], [jjxh], [xlh], [yp], [cshsj], [cshxsy], [cshxsje])"+
                                                   " VALUES('"+map.get("swjg_dm")+"','"+map.get("yq_xlh")+"','"+map.get("jyz_sh")+"','"+map.get("yq_jjxh")+"','"+map.get("yq_xlh")+"','"+map.get("yp_xh")+"','"+map.get("yq_cshsj")+"','"+map.get("yq_cshxsy")+"','"+map.get("yq_cshxsje")+"')");
                        conn.Close();
                        str="<?xml version=\"1.0\" encoding=\"GBK\"?>"
                                        + "<return>" + "<returnCode>1</returnCode>"
                                        + "<returnMessage>上传成功</returnMessage></return>";
                }else{
                        str="<?xml version=\"1.0\" encoding=\"GBK\"?>"
                                        + "<return>" + "<returnCode>0</returnCode>"
                                        + "<returnMessage>XML数据未发现data节点</returnMessage></return>";
                }
                try {
                        d=DocumentHelper.parseText(str);
                } catch (DocumentException e1) {
                        e1.printStackTrace();
                }
                return d;
        }
        /**
         * 插入加油信息
         * @param doc
         * @return
         */
        public Document insertOil(Document doc) {
                Document d=null;
                String str="";
                Map<String, String> map=new HashMap<String, String>();
                Element e=doc.getRootElement();
                List<Element> list=e.elements("data");
                if (list.size()>0) {
                        for (Element element : list) {
                                map.put(element.attributeValue("name"), element.attributeValue("value"));
                        }
                        //存入数据库
                        DBConn conn=new DBConn();
                        //conn.ExecuteSQL("delete from [taxoil].[dbo].[sb] where SWJG_DM='"+map.get("swjg_dm") +"' and yqbh='"+map.get("yq_xlh") +"'  and ny='"+map.get("sb_ny") +"'  and  yl='"+map.get("sb_yl") +"'  and je='"+map.get("sb_je") +"'");
                        if (conn.SelectSQLCount("select * from sb where yqbh='"+map.get("yq_xlh") +"' and ny='"+map.get("sb_ny") +"'")>0){
                                conn.ExecuteSQL("delete from [taxoil].[dbo].[sb] where yqbh='"+map.get("yq_xlh") +"' and ny='"+map.get("sb_ny") +"'");
                        }
                        conn.ExecuteSQL("INSERT INTO [taxoil].[dbo].[sb]([SWJG_DM], [yqbh], [ny], [sbrq], [yl], [je])"+
                                                   " VALUES('"+map.get("swjg_dm")+"','"+map.get("yq_xlh")+"','"+map.get("sb_ny")+"','"+map.get("sb_rq")+"',"+map.get("sb_yl")+","+map.get("sb_je")+")");
                        conn.Close();
                        str="<?xml version=\"1.0\" encoding=\"GBK\"?>"
                                        + "<return>" + "<returnCode>1</returnCode>"
                                        + "<returnMessage>上传成功</returnMessage></return>";
                }else{
                        str="<?xml version=\"1.0\" encoding=\"GBK\"?>"
                                        + "<return>" + "<returnCode>0</returnCode>"
                                        + "<returnMessage>XML数据未发现data节点</returnMessage></return>";
                }
                try {
                        d=DocumentHelper.parseText(str);
                } catch (DocumentException e1) {
                        e1.printStackTrace();
                }
                return d;
        }
}
